package xaj.weavingtest.ast.istype;

import soot.RefType;
import soot.SootClass;

public class Util {

	public static boolean isSubclass(SootClass sc1, String typeName) {
		while (sc1 != null) {
			if (sc1.getName().equals(typeName)) return true;
			try {
				sc1 = sc1.getSuperclass();
			} catch (Exception e) {
				return false;
			}
		}
		return false;
	}

	public static boolean isSubclass(soot.Type t1, String typeName) {
		if (t1 instanceof soot.RefType) {
			soot.RefType rt1 = (soot.RefType) t1;
			return isSubclass(rt1.getSootClass(), typeName);
		}
		return typeName.equals(t1.toString());
	}

	public static boolean isSubclass(String typeName, soot.Type t1) {
		if (typeName.equals(t1.toString())) {
			return true;
		}
		RefType rt2 = soot.Scene.v().getRefType(typeName);
		if (rt2 == null) {
			return false;
		}
		return isSubclass(rt2.getSootClass(), t1.toString());
	}
	
}
